﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HMIS.FrameWork.DomainBase;
using HMIS.FrameWork;
using Iesi.Collections.Generic;

namespace HMIS.Infrastructure.Core.Authority
{
	/// <summary>
	/// 菜单节点
	/// <remarks>在此项目中 菜单层数约定为两层</remarks>
	/// </summary>
	public class MenuNode : TreeNode
	{
		/// <summary>
		/// 菜单名
		/// </summary>
		public override string Name
		{
			get
			{
				return base.Name;
			}
			set
			{
				if (String.IsNullOrEmpty(value))
					throw new NotNullException();
				base.Name = value;
			}
		}

		/// <summary>
		/// 代码
		/// </summary>
		public override string TreeCode
		{
			get
			{
				return base.TreeCode;
			}
			set
			{
				if (String.IsNullOrEmpty(value))
					throw new NotNullException();
				base.TreeCode = value;
			}
		}

		/// <summary>
		/// 节点深度
		/// </summary>
		public override int Level
		{
			get
			{
				return base.Level;
			}
			set
			{
				if (base.Level > 3)
					throw new ValidationException("约定此业务对象的节点深度不超过3");
				base.Level = value;
			}
		}

		/// <summary>
		/// 请求地址
		/// </summary>
		public virtual string ActionName { get; set; }

		/// <summary>
		/// 请求地址
		/// </summary>
		public virtual string ControllerName { get; set; }

		/// <summary>
		/// 小图标
		/// </summary>
		public virtual string SmallIcon { get; set; }

		/// <summary>
		/// 大图标
		/// </summary>
		public virtual string BigIcon { get; set; }

		/// <summary>
		/// 访问地址
		/// <remarks>使用GetURL()函数根据ControllerName和ActionName生成</remarks>
		/// </summary>
		public virtual string URL { get; set; }

		/// <summary>
		/// 根据ControllerName和ActionName生成URL
		/// </summary>
		/// <returns></returns>
		public static string GetURL(string controllerName, string actionName)
		{
			return string.Format("/{0}/{1}", controllerName, actionName);
		}

		/// <summary>
		/// 是否Ext页面
		/// </summary>
		public virtual bool IsExtPage { get; set; }

		/// <summary>
		/// 是否页面功能
		/// </summary>
		public virtual bool IsFunction { get; set; }

		/// <summary>
		/// 排序
		/// </summary>
		public virtual int Index { get; set; }

		/// <summary>
		/// 角色列表
		/// </summary>
		[System.Xml.Serialization.XmlIgnore]
		public virtual Iesi.Collections.Generic.ISet<Role> Roles { get; set; }

		/// <summary>
		/// 用户列表
		/// </summary>
		[System.Xml.Serialization.XmlIgnore]
		public virtual Iesi.Collections.Generic.ISet<Role> Users { get; set; }

		/// <summary>
		/// 被哪些用户设为了常用菜单
		/// </summary>
		[System.Xml.Serialization.XmlIgnore]
		public virtual Iesi.Collections.Generic.ISet<HospUser> FavoritedUsers { get; set; }
	}
}
